package offer;

import java.util.Stack;

public class offer_0031 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        int len1=pushed.length;
        int len2=popped.length;
        Stack<Integer> stack=new Stack<>();
        int index=0;
        for(int i=0;i<len1;++i){
            stack.push(pushed[i]);
            while(!stack.isEmpty()&&stack.peek()==popped[index]){
                stack.pop();
                index++;
            }
        }
        return index==len2;
    }
}